package com.ltedu.user.service.impl;

import com.ltedu.common.contants.Constants;
import com.ltedu.user.domain.LoginLog;
import com.ltedu.user.mapper.LoginLogMapper;
import com.ltedu.user.service.LoginLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 用户登录日志表 服务实现类
 * </p>
 *
 * @author Jerry
 * @since 2020-12-01
 */
@Service
public class LoginLogServiceImpl extends ServiceImpl<LoginLogMapper, LoginLog> implements LoginLogService {

    private Logger logger = LoggerFactory.getLogger(LoginLogServiceImpl.class);

    /**
     * 保存登录日志
     *
     * @param memberId   用户id
     * @param ip         ip地址
     * @param loginState 登录状态
     */
    @Override
    public void saveLoginLog(Long memberId, String ip, Integer loginState) {
        logger.info("LoginLogServiceImpl.save...memberId:{}, ip:{}, loginState:{}", memberId, ip, loginState);
        LoginLog loginLog = new LoginLog();
        loginLog.setMemberId(memberId);
        loginLog.setLoginIp(ip);
        loginLog.setLoginState(Constants.NORMAL);
        loginLog.setLastLoginTime(new Date());
        loginLog.setGmtCreate(new Date());
        logger.info("LoginLogServiceImpl.save...success");
        this.baseMapper.insert(loginLog);
    }
}
